<!-- PersonalView.vue -->
<template>
  <div class="personal container">
    <div class="nav_left">
      <h4>我的账户</h4>
      <div class="nav_left_item">
        <div :class="addClass?'active':''" @click="onAddClass1">个人中心</div>
        <div>消息通知</div>
        <div>个人信息</div>
        <div>安全设置</div>
        <div>地址管理</div>
        <div>我的积分</div>
        <div>我的足迹</div>
        <div>邀请有礼</div>
        <div>幸运抽奖</div>
      </div>
      <h4>交易管理</h4>
      <div class="nav_left_item">
        <div :class="addClass?'':'active'" @click="onAddClass2">我的订单</div>
        <div>优惠券</div>
        <div>礼品卡</div>
        <div>评价晒单</div>
        <div>售后服务</div>
      </div>
      <h4>我的收藏</h4>
      <div class="nav_left_item">
        <div>收藏的商品</div>
        <div>收藏的专题</div>
        <div>关注的品牌</div>
      </div>
      <h4>帮助中心</h4>
      <div class="nav_left_item">
        <div>帮助中心</div>
        <div>在线客服</div>
      </div>
    </div>
    <div class="content_right" v-if="addClass">
      <div class="home_overview">
        <div class="user_meta">
          <div class="avatar">
            <img src="http://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/avatar/2022-05-14/f6bafcfc-a840-4a81-9907-939ee56dff4d.jpg" alt="">
          </div>
          <h4>Did</h4>
        </div>
        <div class="item">
          <div>
            <span class="iconfont icon-huiyuanzhongxin"></span>
            <p>会员中心</p>
          </div>
          <div>
            <span class="iconfont icon-shezhi"></span>
            <p>安全设置</p>
          </div>
          <div>
            <span class="iconfont icon-wxbdingwei"></span>
            <p>地址管理</p>
          </div>
        </div>
      </div>
      <ItemList><h4>我的收藏</h4></ItemList>
      <ItemList><h4>我的足迹</h4></ItemList>
      <GuessView></GuessView>
    </div>

    <div class="content_right order_from" v-if="!addClass">
      <nav>
        <span v-for="item,index in navList" :class="curIndex===index?'active':''" @click="onIndex(index)" :key="item">{{item}}</span>
      </nav>
      <div class="load" v-if="!orderList.items">
        <img src="../assets/load.gif" alt="">
      </div>
      <!-- 订单列表 -->
      <div class="order_list" v-if="orderList.items">
        <OrderItem v-for="item in orderList.items" :key="item.id" :orderList="item">
          <template slot="a">
            <el-button type="info" size="mini" v-if="curIndex===0||curIndex===1">立即付款</el-button>
            <p v-if="curIndex===0||curIndex===1||curIndex===2||curIndex===4||curIndex===6">查看详情</p>
            <p v-if="curIndex===0||curIndex===1">取消订单</p>
            <p v-if="curIndex===2||curIndex===4">再次购买</p>
            <p v-if="curIndex===4">申请售后</p>
          </template>
        </OrderItem>
        <el-pagination
          class="pagination"
          background
          :current-page="page"
          layout="prev, pager, next"
          prev-text="上一页"
          next-text="下一页"
          @prev-click="onPrev"
          @next-click="onNext"
          @current-change="onChange"
          :total="1000">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import ItemList from "../components/personal/ItemList.vue"
import OrderItem from "../components/personal/OrderItem.vue"
import GuessView from '../components/guess/GuessView.vue'
export default {
  name: "PersonalView",
  components: {
    ItemList,
    OrderItem,
    GuessView
  },
  data() {
    return {
      addClass: true,
      onShow: false,
      activeName: 'first',
      navList: ["全部订单","待付款","待发货","待收货","待评价","已完成","已取消"],
      curIndex: 0,
      orderList: [],
      page: 1,
    }
  },
  async created() {
    const res = await this.$http.getOrder({page:"1",pageSize: this.pageSize, orderState: "0"})
    this.orderList = res.data.result;
  },
  methods: {
    onAddClass1() {
      this.addClass = true;
    },
    onAddClass2() {
      this.addClass = false;
    },
    async onIndex(index) {
      this.curIndex = index;
      this.page = 1;
      this.orderList = [];
      const res = await this.$http.getOrder({page: this.page+"",pageSize:"10",orderState: this.curIndex+""})
      this.orderList = res.data.result;
    },
    async onPrev() {
      console.log(1);
      this.orderList = [];
      if(this.page<=0) {
        this.page = 1;
      }else {
        --this.page;
      }
      const res = await this.$http.getOrder({page: this.page+"",pageSize:"10",orderState: this.curIndex+""})
      this.orderList = res.data.result;
      console.log(this.orderList);
    },
    async onNext() {
      console.log(1);
      this.orderList = [];
      ++this.page;
      const res = await this.$http.getOrder({page: this.page+"",pageSize:"10",orderState: this.curIndex+""})
      this.orderList = res.data.result;
      console.log(this.orderList);
    },
    async onChange(e) {
      console.log(e);
      this.orderList = [];
      this.page = e;
      const res = await this.$http.getOrder({page: this.page+"",pageSize:"10",orderState: this.curIndex+""})
      this.orderList = res.data.result;
      console.log(this.orderList);
    }
  }
}
</script>
<style lang='scss' scoped>
@font-face {
  font-family: "iconfont"; /* Project id 3707001 */
  src: url('//at.alicdn.com/t/c/font_3707001_4j26tudp91.woff2?t=1667132459381') format('woff2'),
       url('//at.alicdn.com/t/c/font_3707001_4j26tudp91.woff?t=1667132459381') format('woff'),
       url('//at.alicdn.com/t/c/font_3707001_4j26tudp91.ttf?t=1667132459381') format('truetype');
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-wxbdingwei:before {
  content: "\e624";
}

.icon-shezhi:before {
  content: "\e8b7";
}

.icon-huiyuanzhongxin:before {
  content: "\e660";
}

.personal {
  display: flex;
  padding-top: 20px;
  box-sizing: border-box;
  .nav_left {
    width: 220px;
    margin-right: 20px;
    border-radius: 2px;
    background-color: #fff;

    h4 {
      font-size: 18px;
      font-weight: 400;
      padding: 20px 52px 5px;
      border-top: 1px sodivd #f6f6f6;
    }

    .nav_left_item {
      padding: 0 52px 10px;

      div {
        line-height: 1;
        padding: 15px 0;
        font-size: 14px;
        color: #666;
        position: relative;
        cursor: pointer;
      }

      div.active {
        color: #27ba9b;
      }

      div.active::before {
        content: "";
        display: block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        position: absolute;
        top: 19px;
        left: -16px;
        background-color: #27ba9b;
      }
    }
  }

  .content_right {
    width: 1000px;
    box-sizing: border-box;
    .home_overview {
      height: 132px;
      background: url(http://erabbit.itheima.net/img/center-bg.31e0daef.png) no-repeat 50%/cover;
      display: flex;
      .user_meta {
        flex: 1;
        display: flex;
        align-items: center;
        .avatar {
          width: 85px;
          height: 85px;
          border-radius: 50%;
          overflow: hidden;
          margin-left: 60px;
          img {
            max-width: 100%;
            max-height: 100%;
            vertical-align: middle;
          }
        }
        h4 {
          padding-left: 26px;
          font-size: 18px;
          font-weight: 400;
          color: #fff;
        }
      }
      .item {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-around;
        div {
          color: #fff;
          font-size: 16px;
          text-align: center;
          span {
            font-size: 32px;
          }
          p {
            line-height: 32px;
          }
        }
      }
    }
  }
  .order_from {
    background-color: #fff;
    nav {
      height: 60px;
      line-height: 60px;
      display: flex;
      border-bottom: 1px solid #f5f5f5;
      box-sizing: border-box;
      span {
        width: 110px;
        border-right: 1px solid #f5f5f5;
        text-align: center;
        font-size: 16px;
        cursor: pointer;
      }
      span.active {
        border-top: 2px solid #27ba9b;
          height: 60px;
          background: #fff;
          line-height: 56px;
        }
    }
    .load {
      width: 60px;
      height: 60px;
      margin: 100px auto;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .order_list {
      background: #fff;
      padding: 20px;
      position: relative;
      min-height: 400px;
      .pagination {
        display: inline-block;
        position: relative;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
}
</style>